package com.gis.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gis.dto.NodeDataDTO;
import com.gis.entity.NodeData;
import com.gis.result.ResponseResult;
import com.gis.service.NodeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.RequestBody;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Slf4j
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequiredArgsConstructor
@RequestMapping("/node")
@Tag(name = "[算法]节点", description = "节点数据接口")
public class NodeController {
    @Autowired
    private NodeService nodeService;

    @Operation(summary = "获取所有节点")
    @GetMapping("/getAllNode")
    public ResponseResult<List<NodeData>> getAllNodes() {
        List<NodeData> nodes = nodeService.listAllNode();
        return ResponseResult.success(nodes);
    }

    @Operation(summary = "删除节点")
    @GetMapping("/deleteNode")
    public ResponseResult<String> deleteNode(@RequestParam Long nodeId) {
        boolean result = nodeService.removeById(nodeId);
        if (result) {
            return ResponseResult.success("删除成功");
        } else {
            return ResponseResult.fail("删除失败");
        }
    }

    @Operation(summary = "添加节点")
    @PostMapping("/addnode")
    public ResponseResult<String> createNode(@RequestBody NodeData node) {
        boolean result = nodeService.save(node);
        if (node != null) {
            result = true;
        }
        if (result) {
            return ResponseResult.success("添加成功");
        } else {
            return ResponseResult.fail("添加失败");
        }
    }
    
    
}
